package cn.clwxy.gdz.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.clwxy.gdz.bo.OrderImformation;
import cn.clwxy.gdz.dao.OrderDao;
import cn.clwxy.gdz.dao.OrderDaoImpl;
import cn.clwxy.gdz.util.JsonSerializeHelper;

public class OrderImformationServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date orderBeginTime = new Date();
		try {
			orderBeginTime = simpleDateFormat.parse(request
					.getParameter("orderBeginTime"));
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String studentcomment=request.getParameter("studentcomment");
		String teachercomment=request.getParameter("teachercomment");
		String teacherRealName=request.getParameter("teacherRealName");
		String teacherPhone=request.getParameter("teacherPhone");
		String studentName=request.getParameter("studentName");
		String studentPhone=request.getParameter("studentPhone");
		String subjectName=request.getParameter("subjectName");
		Integer OrderId;

		try {
			OrderId = Integer.parseInt(request.getParameter("OrderId"));
		
		OrderDao orderDao = new OrderDaoImpl();
		OrderImformation orderImformation = orderDao.findOderByOrderId(OrderId);
		orderImformation.setOrderBeginTime(orderBeginTime);
		orderImformation.setStudentcomment(studentcomment);
		orderImformation.setTeachercomment(teachercomment);
		orderImformation.setTeacherRealName(teacherRealName);
		orderImformation.setTeacherPhone(teacherPhone);
		orderImformation.setStudentName(studentName);
		orderImformation.setStudentPhone(studentPhone);
		orderImformation.setSubjectName(subjectName);

		String json = JsonSerializeHelper.JsonSerializer(orderImformation);
		response.getWriter().write(json);
		} catch (NumberFormatException e) {
			response.getWriter().write(0);
			e.printStackTrace();
		}
		
	}

}
